package init;

import objects.CarBase;
import objects.CarNodeStore;
import objects.LinkNode;
import utils.Roulette;

import java.util.LinkedList;
import java.util.List;

/**
 * @author whn
 * 用于创建车辆的链接链路
 */
public class InitLine {
    public static void init(CarNodeStore carNodeStore) {
        List<CarBase> carBaseList = carNodeStore.getCarList();
        int[][] relation = carNodeStore.getRelation();
        double[][] ability = carNodeStore.getAbility();
        double[][] probability = carNodeStore.getProbability();
        List<Integer> linkIndex = carNodeStore.getLinkIndex();
        int index = 0;
        LinkNode head = new LinkNode(0, carBaseList.get(0), 0, null, null);
        linkIndex.add(0);
        LinkNode cur = head;
        for (int i = 0; i < carBaseList.size(); ) {
            // TODO:编写链接建立方法，根据能力来轮盘赌，根据轮盘赌的规则选择最大的那个概率。
            // TODO:还少一个全局信息素存储列，或者在链表中存，迭代中遍历减少信息素。当发现有信息素跌到阈值立刻修复。
            int j = Roulette.getResult(probability[i]);
            LinkNode node = new LinkNode(j, carBaseList.get(j), ability[i][j], cur, null);
            linkIndex.add(j);
            index++;
            cur.setNext(node);
            cur = node;
            i = j;
            if (i==14){
                break;
            }
        }
    }
}
